#include <bits/stdc++.h>
using namespace std;

inline int read(){
	int x = 0, f = 1;
	char c = getchar();
	for(; c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
	for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
	return f * x;
}

const int N = 1e5 + 9;
const double eps = 1e-9;
int d[N], v[N], a[N], p[N];
int n, m, l, V, ans1, ans2;

void solve(){
	ans1 = ans2 = 0;
	bool fa = 1, fb = 1;
	n = read(); m = read(); l = read(); V = read();
	for(int i = 1; i <= n; i++){
		d[i] = read(); v[i] = read(); a[i] = read();
		if(a[i]) fa = 0;
		if(a[i] < 0) fb = 0;
	}
	for(int i = 1; i <= m; i++) p[i] = read();
	if(fa){
		for(int i = 1; i <= n; i++) {
			if(v[i] > V){
				if(d[i] <= p[m]){
					ans1++;
				}
			}
		}
		ans2 = (ans1) ? m - 1 : m;
		cout << ans1 << ' ' << ans2 << endl;
		return;
	}
	if(fb){
		int s = p[m];
		for(int i = 1; i <= n; i++){
			double vt;
			vt = (a[i]) ? sqrt(v[i] * v[i] + 2 * a[i] * s) : v[i];
			if(vt - V > eps && d[i] <= p[m]) ans1++;
		}
		ans2 = (ans1) ? m - 1 : m;
		cout << ans1 << ' ' << ans2 << endl;
	}
}

int main(){
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	int T; cin >> T;
	while(T--) solve();
	return 0;
}
//freopen
//filename
